/* eslint-disable*/
// import glb from './feiji.gltf'
import img from "./nc.png";

export default class Plane {
	constructor(viewer, position, name) {
		this.viewer = viewer;
		viewer.scene.globe.enableLighting = true;

		var data = [
			{
				longitude: 116.36578323959371,
				latitude: 39.94717447037612,
				height: 200,
				time: 0,
			},
			{
				longitude: 116.40200620078545,
				latitude: 39.94788986593708,
				height: 200,
				time: 90,
			},
			{
				longitude: 116.40126332543285,
				latitude: 39.9870228957151,
				height: 200,
				time: 180,
			},
			{
				longitude: 116.36315522148672,
				latitude: 39.985919757736404,
				height: 200,
				time: 270,
			},
			{
				longitude: 116.36578323959371,
				latitude: 39.94717447037612,
				height: 200,
				time: 360,
			},
		];

		var start = Cesium.JulianDate.fromDate(new Date(2017, 7, 11));
		// 结束时间
		var stop = Cesium.JulianDate.addSeconds(
			start,
			360,
			new Cesium.JulianDate()
		);

		// 设置始时钟始时间
		viewer.clock.startTime = start.clone();
		// 设置时钟当前时间
		viewer.clock.currentTime = start.clone();
		// 设置始终停止时间
		viewer.clock.stopTime = stop.clone();
		// 时间速率，数字越大时间过的越快
		viewer.clock.multiplier = 10;
		// 时间轴
		// viewer.timeline.zoomTo(start, stop);
		// 循环执行,即为2，到达终止时间，重新从起点时间开始
		viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP;

		/**
		 * 计算飞行
		 * @param source 数据坐标
		 * @returns {SampledPositionProperty|*}
		 */
		function computeFlight(source) {
			// 取样位置 相当于一个集合
			var property = new Cesium.SampledPositionProperty();
			for (var i = 0; i < source.length; i++) {
				var time = Cesium.JulianDate.addSeconds(
					start,
					source[i].time,
					new Cesium.JulianDate()
				);
				var position = Cesium.Cartesian3.fromDegrees(
					source[i].longitude,
					source[i].latitude,
					source[i].height
				);
				// 添加位置，和时间对应
				property.addSample(time, position);
			}
			return property;
		}

		var property = computeFlight(data);

		// 添加模型
		this.planeEntity = viewer.entities.add({
			// 和时间轴关联
			availability: new Cesium.TimeIntervalCollection([
				new Cesium.TimeInterval({
					start: start,
					stop: stop,
				}),
			]),
			position: property,
			// 根据所提供的速度计算模型的朝向
			orientation: new Cesium.VelocityOrientationProperty(property),
			// 模型数据
			model: {
				uri: "./data/city/feiji.gltf",
				minimumPixelSize: 500,
				maximumScale: 50,
				scaleByDistance: new Cesium.NearFarScalar(1e2, 1, 1e5, 0),
				// color: Cesium.Color.CYAN.withAlpha(0.8)
			},
			label: {
				text: "无人机",
				font: "16px sans-serif",
				pixelOffset: new Cesium.Cartesian3(0, -50, -1000),
				eyeOffset: new Cesium.Cartesian3(0, 0, -10),
				fillColor: Cesium.Color.AQUAMARINE,
				scaleByDistance: new Cesium.NearFarScalar(1e2, 1.5, 1e5, 0),
				pixelOffsetScaleByDistance: new Cesium.NearFarScalar(
					1e2,
					1,
					1e5,
					0.1
				),
			},
		});

		this.imgEntity = viewer.entities.add({
			// 和时间轴关联
			availability: new Cesium.TimeIntervalCollection([
				new Cesium.TimeInterval({
					start: start,
					stop: stop,
				}),
			]),
			position: property,
			ellipse: {
				semiMinorAxis: 200.0,
				semiMajorAxis: 200.0,
				material: img,
				// clampToGround: true,
			},
		});
	}

	changeShow(show) {}

	remove() {}
}
